﻿using System;

namespace diantou.web.emanagement
{
    /// <summary>
    /// 题目编辑
    /// </summary>
    abstract class questionEdit<viewType> : permissionView<viewType>
        where viewType : questionEdit<viewType>
    {
        /// <summary>
        /// 题目
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        protected diantou.examDataAccess.examQuestion question;
        /// <summary>
        /// 是否能添加题目
        /// </summary>
        protected virtual bool canAppend
        {
            get { return true; }
        }
        /// <summary>
        /// 考试类型
        /// </summary>
        protected abstract dataModel.examQuestion.type type { get; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="questionId"></param>
        /// <returns></returns>
        protected bool loadView(int questionId)
        {
            if ((currentUser.Permission & dataModel.user.permission.ExamEditor) != 0)
            {
                if (questionId == 0)
                {
                    if (canAppend)
                    {
                        question = diantou.examDataAccess.examQuestion.NullQuestion;
                        return true;
                    }
                }
                else
                {
                    question = examDataAccess.clientCache.ExamQuestion[questionId];
                    if (question != null)
                    {
                        if (question.IsExamEditor(currentUser))
                        {
                            return true;
                        }
                        question = null;
                    }
                }
                AjaxResponse(webConfig.NotFound404);
                return false;
            }
            AjaxResponse(new fastCSharp.code.cSharp.webView.errorPath { ErrorPath = currentUser.Path.NewFocus });
            return false;
        }
    }
}
